//
//  SISSMapShowViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/6/6.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSMapShowViewController.h"
#import "SISSBaseTableView.h"
#import "SISSButton.h"
#import "SISSJsonRequestNetworkingManager+Resources.h"
#import "SISSNetworkingManager+Home.h"

#import "SISSHousingCell.h"
#import "SISSHouseResourceDetailVC.h"
#import "SISSRecommendPassengerViewController.h"

#import "SISSPassengerCell.h"
#import "SISSPassengerResourceDetailVC.h"
#import "SISSRecommendHouseViewController.h"

#import "SISSCommonRentCell.h"
#import "SISSRecommendTenantViewController.h"
#import "SISSRentOutDetailViewController.h"

#import "SISSRecommendRentOutViewController.h"
#import "SISSTenantDetailViewController.h"

static NSString *mapHouseCellReuseID = @"mapHouseCellReuseID";
static NSString *mapPassengerCellReuseID = @"mapPassengerCellReuseID";
static NSString *commonRentCellReuseID = @"commonRentCellReuseID";
@interface SISSMapShowViewController ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,SISSHousingCellDelegate,SISSPassengerCellDelegate,SISSCommonRentCellDelegate>

/**
 区域label
 */
@property (weak, nonatomic) UILabel *regionLabel;
/**
 数量label
 */
@property (weak, nonatomic) UILabel *countLabel;
/**
 tableView
 */
@property (strong, nonatomic) SISSBaseTableView *tableView;

/** 房源数组 */
@property (strong, nonatomic) NSMutableArray<SISSHouseResourceModel *> *houseResourceArr;
/** 客源数组 */
@property (strong, nonatomic) NSMutableArray<SISSPassengerResourceModel *> *passengerResourceArr;
@property (strong, nonatomic) NSMutableArray<SISSRentOutModel *> *rentOutArr;
@property (strong, nonatomic) NSMutableArray<SISSTenantModel *> *tenantArr;

/** 排序规则 */
@property (assign, nonatomic) NSInteger orderAttrs;


@end

@implementation SISSMapShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    __weak typeof(self) weakSelf = self;
    [kSISSRefresh prepareHeaderRefresh:self.tableView loadDataBlock:^{
        kSISSRefresh.refreshType = SISSRefressTypeUpDown;
        [weakSelf upDownLoadData];
    }];
    
    
//    [kSISSRefresh prepareFooterRefresh:self.tableView reloadDataBlock:^{
//        kSISSRefresh.refreshType = SISSRefressTypeReloadMore;
//        [weakSelf reloadMoreData];
//    }];
}

- (void)setArea:(NSString *)area {
    _area = area;
    
    self.regionLabel.text = area;
}

- (void)setParameters:(NSDictionary *)parameters {
    
    _parameters = parameters;
    
    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
           [self requestFilterHouseResourceData];
        }
            break;
        case SISSMapShowTypePassenger: {
            [self requestPassengerResourceData];
        }
            break;
        case SISSMapShowTypeRentOut: {
            [self requestRentOutData];
        }
            break;
        case SISSMapShowTypeTenant: {
            [self requestTenantData];
        }
            break;
            
        default:
            break;
    }
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.pageNo = 1;
   
    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
            [self requestFilterHouseResourceData];
        }
            break;
        case SISSMapShowTypePassenger: {
            [self requestPassengerResourceData];
        }
            break;
        case SISSMapShowTypeRentOut: {
            [self requestRentOutData];
        }
            break;
        case SISSMapShowTypeTenant: {
            [self requestTenantData];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 上下拉刷新加载方法
- (void)upDownLoadData {
    
    self.pageNo = 1;
   
    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
            [self requestFilterHouseResourceData];
        }
            break;
        case SISSMapShowTypePassenger: {
            [self requestPassengerResourceData];
        }
            break;
        case SISSMapShowTypeRentOut: {
            [self requestRentOutData];
        }
            break;
        case SISSMapShowTypeTenant: {
            [self requestTenantData];
        }
            break;
            
        default:
            break;
    }
}

- (void)reloadMoreData {
    
    self.pageNo += 1;
   
    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
            [self requestFilterHouseResourceData];
        }
            break;
        case SISSMapShowTypePassenger: {
            [self requestPassengerResourceData];
        }
            break;
        case SISSMapShowTypeRentOut: {
            [self requestRentOutData];
        }
            break;
        case SISSMapShowTypeTenant: {
            [self requestTenantData];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 请求房源、客源数据
/**
 房源数据
 */
- (void)requestFilterHouseResourceData {
    
    NSInteger orderAttrs = self.orderAttrs ? self.orderAttrs : 0;
    NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:self.parameters];
    [parameter setObject:@(orderAttrs) forKey:@"orderAttrs"];
    
    // 加载搜索跳转找房源的数据
    [kJsonRequestNetworkingManager requestFilterSearchHouseResourceWithPageNo:1 parameters:parameter success:^(SISSBasePagingModel *baseModel) {
        
        NSArray *houseResources = [NSArray yy_modelArrayWithClass:[SISSHouseResourceModel class] json:baseModel.data];
        
        if (self.houseResourceArr.count != 0 && kSISSRefresh.refreshType == SISSRefressTypeUpDown) {
            
            [self.houseResourceArr removeAllObjects];
        }
        
        for (int i = 0; i < houseResources.count; i++) {
            
            [self.houseResourceArr addObject:houseResources[i]];
        }
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            
            self.countLabel.text = [NSString stringWithFormat:@"共找到%zd条符合条件的信息",self.houseResourceArr.count];
            
            [self.tableView reloadData];
            
            [self.tableView.mj_header endRefreshing];
            [self.tableView.mj_footer endRefreshing];
        }];
        
    } failed:^(NSError *error) {
        
        NSLog(@"%@",error);
    }];
}

/**
 客源数据
 */
- (void)requestPassengerResourceData {
    
    NSInteger orderAttrs = self.orderAttrs ? self.orderAttrs : 0;
    NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:self.parameters];
    [parameter setObject:@(orderAttrs) forKey:@"orderAttrs"];
    
    [kJsonRequestNetworkingManager requestFilterSearchPassengerResourceWithPageNo:1 parameters:parameter success:^(SISSBasePagingModel *baseModel) {
        
        NSArray *passengerResources = [NSArray yy_modelArrayWithClass:[SISSPassengerResourceModel class] json:baseModel.data];
        
        if (self.passengerResourceArr.count != 0 && kSISSRefresh.refreshType == SISSRefressTypeUpDown) {
            
            [self.passengerResourceArr removeAllObjects];
        }
        
        for (int i = 0; i < passengerResources.count; i++) {
            
            [self.passengerResourceArr addObject:passengerResources[i]];
        }
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            
            self.countLabel.text = [NSString stringWithFormat:@"共找到%zd条符合条件的信息",self.passengerResourceArr.count];
            
            [self.tableView reloadData];
            
            [self.tableView.mj_header endRefreshing];
            [self.tableView.mj_footer endRefreshing];
        }];
        
    } failed:^(NSError *error) {
        
        NSLog(@"%@",error);
    }];
}


/**
 出租
 */
- (void)requestRentOutData {
    NSInteger orderAttrs = self.orderAttrs ? self.orderAttrs : 0;
    NSDictionary *parameter = @{
                                @"spId":[SISSUserAccount shared].spId,
                                @"saId":[SISSUserAccount shared].saId,
                                @"soId":[SISSUserAccount shared].soId,
                                @"sobId":[SISSUserAccount shared].sobId,
                                @"orderAttrs":@(orderAttrs),
                                @"pageSize":@(20),
                                @"pageNo":@(self.pageNo),
                                };
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameter];
    [params addEntriesFromDictionary:self.parameters];

    WeakSelf
    [kJsonRequestNetworkingManager requestFilterRentOutResourceCooperationWithParameters:params success:^(SISSBasePagingModel *baseModel) {
        
        NSArray *rentOutResources = [NSArray yy_modelArrayWithClass:[SISSRentOutModel class] json:baseModel.data];
        
        if (weakSelf.rentOutArr.count != 0 && kSISSRefresh.refreshType == SISSRefressTypeUpDown) {
            
            [weakSelf.rentOutArr removeAllObjects];
        }
        
        for (int i = 0; i < rentOutResources.count; i++) {
            
            [weakSelf.rentOutArr addObject:rentOutResources[i]];
        }
        weakSelf.countLabel.text = [NSString stringWithFormat:@"共找到%zd条符合条件的信息",weakSelf.rentOutArr.count];

        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            
            [weakSelf.tableView reloadData];
            
            [weakSelf.tableView.mj_header endRefreshing];
            [weakSelf.tableView.mj_footer endRefreshing];
            if (weakSelf.rentOutArr.count >= baseModel.total) {
//                weakSelf.pageNo = baseModel.totalPages;
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }];
        
        
    } failed:^(NSError *error) {
        [weakSelf.tableView.mj_header endRefreshing];
        [weakSelf.tableView.mj_footer endRefreshing];
        NSLog(@"%@",error);
    }];
}

/**
 租客
 */
- (void)requestTenantData {
    NSInteger orderAttrs = self.orderAttrs ? self.orderAttrs : 0;
    NSDictionary *parameter = @{
                                @"spId":[SISSUserAccount shared].spId,
                                @"saId":[SISSUserAccount shared].saId,
                                @"soId":[SISSUserAccount shared].soId,
                                @"sobId":[SISSUserAccount shared].sobId,
                                @"orderAttrs":@(orderAttrs),
                                @"pageSize":@(20),
                                @"pageNo":@(self.pageNo),
                                };
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameter];
    [params addEntriesFromDictionary:self.parameters];
    WeakSelf
    [kJsonRequestNetworkingManager requestFilterTenantResourceCooperationWithParameters:params success:^(SISSBasePagingModel *baseModel) {
        
        NSArray *tenantResources = [NSArray yy_modelArrayWithClass:[SISSTenantModel class] json:baseModel.data];
        
        if (weakSelf.tenantArr.count != 0 && kSISSRefresh.refreshType == SISSRefressTypeUpDown) {
            
            [weakSelf.tenantArr removeAllObjects];
        }
        
        for (int i = 0; i < tenantResources.count; i++) {
            
            [weakSelf.tenantArr addObject:tenantResources[i]];
        }
        
        weakSelf.countLabel.text = [NSString stringWithFormat:@"共找到%zd条符合条件的信息",weakSelf.tenantArr.count];
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            
            [weakSelf.tableView reloadData];
            
            [weakSelf.tableView.mj_header endRefreshing];
            [weakSelf.tableView.mj_footer endRefreshing];
            if (weakSelf.tenantArr.count >= baseModel.total) {
//                weakSelf.pageNo = baseModel.totalPages;
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }];
        
        
    } failed:^(NSError *error) {
        [weakSelf.tableView.mj_header endRefreshing];
        [weakSelf.tableView.mj_footer endRefreshing];
        NSLog(@"%@",error);
    }];
}

#pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
            return self.houseResourceArr.count;
        }
            break;
        case SISSMapShowTypePassenger: {
            return self.passengerResourceArr.count;
        }
            break;
        case SISSMapShowTypeRentOut: {
            return self.rentOutArr.count;
        }
            break;
        case SISSMapShowTypeTenant: {
            return self.tenantArr.count;
        }
            break;
            
        default:
            return 0;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
            SISSHousingCell *cell = [tableView dequeueReusableCellWithIdentifier:mapHouseCellReuseID];
            cell.delegate = self;
            cell.houseResourceModel = self.houseResourceArr[indexPath.row];
            
            return cell;
        }
            break;
        case SISSMapShowTypePassenger: {
            SISSPassengerCell *cell = [tableView dequeueReusableCellWithIdentifier:mapPassengerCellReuseID];
            cell.delegate = self;
            
            cell.passengerModel = self.passengerResourceArr[indexPath.row];
            
            return cell;
        }
            break;
        case SISSMapShowTypeRentOut:
        case SISSMapShowTypeTenant: {
            SISSCommonRentCell *cell = [tableView dequeueReusableCellWithIdentifier:commonRentCellReuseID forIndexPath:indexPath];
            cell.delegate = self;
            if (self.mapShowType == SISSMapShowTypeRentOut) {
                cell.rentOutModel = self.rentOutArr[indexPath.row];
            } else if (self.mapShowType == SISSMapShowTypeTenant)  {
                cell.tenantModel = self.tenantArr[indexPath.row];
            }
            return cell;
        }
            break;
            
        default:
            return nil;
            break;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; // 去除tableView的选中状态
    
    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
            
            SISSHouseResourceDetailVC *vc = [[SISSHouseResourceDetailVC alloc] init];
            vc.title = @"房源详情";
            vc.isFind = YES;
            SISSHouseResourceModel *houseModel = self.houseResourceArr[indexPath.row];
            vc.houseResourceModel = houseModel;
            if (houseModel.read != 1) {
                
                [kNetworkManager setHouseResourceReadWithHouseId:houseModel.ID success:^(id responseObject) {
                    
                    if ([responseObject[@"code"] integerValue] == 200) {
                        NSLog(@"插入成功！");
                    }
                    
                } failed:^(NSError *error) {
                    
                    NSLog(@"%@",error);
                }];
            }
            self.houseResourceArr[indexPath.row].read = 1;
            [self.tableView reloadData];
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case SISSMapShowTypePassenger: {
            
            SISSPassengerResourceDetailVC *vc = [[SISSPassengerResourceDetailVC alloc] init];
            vc.title = @"客源详情";
            vc.isFind = YES;
            SISSPassengerResourceModel *passengerModel = self.passengerResourceArr[indexPath.row];
            if (!passengerModel.read) {
                
                [kNetworkManager setPassengerResourceReadWithPassengerId:passengerModel.ID success:^(id responseObject) {
                    
                    if ([responseObject[@"code"] integerValue] == 200) {
                        NSLog(@"插入成功！");
                    }
                } failed:^(NSError *error) {
                    
                    NSLog(@"%@",error);
                }];
            }
            vc.passengerModel = passengerModel;
            self.passengerResourceArr[indexPath.row].read = 1;
            [self.tableView reloadData];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case SISSMapShowTypeRentOut: {
            SISSRentOutDetailViewController *vc = [[SISSRentOutDetailViewController alloc] init];
            vc.title = @"房源详情";
            vc.isFind = YES;
            SISSRentOutModel *rentOutModel = self.rentOutArr[indexPath.row];
            vc.rentOutModel = rentOutModel;
            if (rentOutModel.read != 1) {
                
                [kNetworkManager setRentOutResourceReadWithRentOutId:rentOutModel.ID success:^(id responseObject) {
                    
                    if ([responseObject[@"code"] integerValue] == 200) {
                        NSLog(@"插入成功！");
                    }
                    
                } failed:^(NSError *error) {
                    
                    NSLog(@"%@",error);
                }];
            }
            self.rentOutArr[indexPath.row].read = 1;
            [self.tableView reloadData];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case SISSMapShowTypeTenant: {
            SISSTenantDetailViewController *vc = [[SISSTenantDetailViewController alloc] init];
            vc.title = @"租客详情";
            vc.isFind = YES;
            SISSTenantModel *tenantModel = self.tenantArr[indexPath.row];
            vc.tenantModel = tenantModel;
            if (tenantModel.read != 1) {
                
                [kNetworkManager setTenantResourceReadWithTenantId:tenantModel.ID success:^(id responseObject) {
                    
                    if ([responseObject[@"code"] integerValue] == 200) {
                        NSLog(@"插入成功！");
                    }
                    
                } failed:^(NSError *error) {
                    
                    NSLog(@"%@",error);
                }];
            }
            self.tenantArr[indexPath.row].read = 1;
            [self.tableView reloadData];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        default:
            break;
    }
}


#pragma mark - SISSHousingCellDelegate
- (void)housingCellRecommendButtonDidClick:(UIButton *)button {
    
    SISSHousingCell *cell = (SISSHousingCell *)button.nextResponder.nextResponder;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    SISSHouseResourceModel *model = self.houseResourceArr[indexPath.row];
    
    SISSRecommendPassengerViewController *vc = [[SISSRecommendPassengerViewController alloc] init];
    vc.title = @"推荐客源";
    vc.isFind = YES;
    vc.ahrId = model.ID;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - SISSPassengerCellDelegate
- (void)passengerCellRecommendButtonDidClick:(UIButton *)button {
    
    SISSPassengerCell *cell = (SISSPassengerCell *)button.nextResponder.nextResponder;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    SISSPassengerResourceModel *model = self.passengerResourceArr[indexPath.row];
    
    SISSRecommendHouseViewController *vc = [[SISSRecommendHouseViewController alloc] init];
    vc.title = @"推荐房源";
    vc.isFind = YES;
    vc.abdId = model.ID;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - SISSCommonRentCellDelegate
- (void)commonRentCellRecommendButtonDidClick:(UIButton *)button {
    SISSCommonRentCell *cell = (SISSCommonRentCell *)button.nextResponder.nextResponder;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    if (self.mapShowType == SISSMapShowTypeRentOut) {
        SISSRentOutModel *model = self.rentOutArr[indexPath.row];
        SISSRecommendTenantViewController *vc = [[SISSRecommendTenantViewController alloc] init];
        vc.title = @"推荐租客";
        vc.isFind = YES;
        vc.alrId = model.ID;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        SISSTenantModel *model = self.tenantArr[indexPath.row];
        SISSRecommendRentOutViewController *vc = [[SISSRecommendRentOutViewController alloc] init];
        vc.title = @"推荐出租";
        vc.isFind = YES;
        vc.arrId = model.ID;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark - 按钮点击事件
- (void)sortButtonClickAction {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    alertController.view.tintColor = [UIColor blackColor];
    [alertController addTapDisMissAction];
    
    switch (self.mapShowType) {
        case SISSMapShowTypeHouse: {
            
            NSArray *sortArr = @[@"默认排序", @"售价从低到高", @"售价从高到低", @"均价从低到高", @"均价从高到低"];
            for (int i = 0; i < sortArr.count; i++) {
                UIAlertAction *action = [UIAlertAction actionWithTitle:sortArr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                    self.orderAttrs = i;
                    [self requestFilterHouseResourceData];
                }];
                
                [alertController addAction:action];
            }
        }
            break;
        case SISSMapShowTypePassenger: {
            
            NSArray *sortArr = @[@"默认排序", @"预算从低到高", @"预算从高到低"];
            
            for (int i = 0; i < sortArr.count; i++) {
                UIAlertAction *action = [UIAlertAction actionWithTitle:sortArr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                    self.orderAttrs = i;
                    
                    [self requestPassengerResourceData];
                }];
                
                [alertController addAction:action];
            }
        }
            break;
        case SISSMapShowTypeRentOut: {
            NSArray *sortArr = @[@"默认排序", @"租金从低到高", @"租金从高到低"];
            
            for (int i = 0; i < sortArr.count; i++) {
                UIAlertAction *action = [UIAlertAction actionWithTitle:sortArr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                    self.orderAttrs = i;
                    kSISSRefresh.refreshType = SISSRefressTypeUpDown;
                    self.pageNo = 1;
                    [self requestRentOutData];
                }];
                
                [alertController addAction:action];
            }
        }
            break;
        case SISSMapShowTypeTenant: {
            NSArray *sortArr = @[@"默认排序", @"租金预算从低到高", @"租金预算从高到低"];
            
            for (int i = 0; i < sortArr.count; i++) {
                UIAlertAction *action = [UIAlertAction actionWithTitle:sortArr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                    self.orderAttrs = i;
                    kSISSRefresh.refreshType = SISSRefressTypeUpDown;
                    self.pageNo = 1;
                    [self requestTenantData];
                }];
                
                [alertController addAction:action];
            }
        }
            break;
            
        default:
            break;
    }
    [self presentViewController:alertController animated:YES completion:nil];
    
}

- (void)shrinkButtonClickAction {
    
    if ([self.delegate respondsToSelector:@selector(shrinkButtonClickAction)]) {
        [self.delegate shrinkButtonClickAction];
    }
    
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 区域label
    UILabel *regionLabel = [[UILabel alloc] init];
    regionLabel.font = [UIFont systemFontOfSize:15];
    regionLabel.textColor = COLOR(0x334A60);
    regionLabel.text = @"福田";
    [self.view addSubview:regionLabel];
    self.regionLabel = regionLabel;
    
    // 数量label
    UILabel *countLabel = [[UILabel alloc] init];
    countLabel.font = [UIFont systemFontOfSize:11];
    countLabel.textColor = COLOR(0x8998A5);
    countLabel.text = @"共找到 条符合条件的信息";
    [self.view addSubview:countLabel];
    self.countLabel = countLabel;
    
    // 线
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:lineView];
    
    // 排序按钮
    SISSButton *sortButton = [SISSButton buttonWithType:UIButtonTypeCustom];
    [sortButton setImage:[UIImage imageNamed:@"排序"] forState:UIControlStateNormal];
    [sortButton setTitle:@"排序" forState:UIControlStateNormal];
    [sortButton addTarget:self action:@selector(sortButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:sortButton];
    
    // 右侧竖线
    UIView *verticalLineView = [[UIView alloc] init];
    verticalLineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:verticalLineView];
    
    // 右侧收起按钮
    SISSButton *shrinkButton = [SISSButton buttonWithType:UIButtonTypeCustom];
    [shrinkButton setImage:[UIImage imageNamed:@"收起"] forState:UIControlStateNormal];
    [shrinkButton setTitle:@"收起" forState:UIControlStateNormal];
    [shrinkButton addTarget:self action:@selector(shrinkButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shrinkButton];
    
    // tableView
    [self.view addSubview:self.tableView];
    
    // 自动布局
    [regionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).offset(8);
        make.top.mas_equalTo(self.view).offset(10);
    }];
    
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(regionLabel);
        make.top.equalTo(regionLabel.mas_bottom).offset(4);
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(countLabel.mas_bottom).offset(16).priority(999);
        make.height.mas_equalTo(1).priority(999);
    }];
    
    [shrinkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-8);
    }];
    
    [verticalLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(shrinkButton);
        make.right.equalTo(shrinkButton.mas_left).offset(-8);
        make.width.mas_equalTo(1);
    }];
    
    [sortButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(shrinkButton);
        make.right.equalTo(verticalLineView.mas_left).offset(-8);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(lineView.mas_bottom);
    }];
}



#pragma mark - Getter & Setter
- (SISSBaseTableView *)tableView {
    if (!_tableView) {
        _tableView = [[SISSBaseTableView alloc] init];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        // 自动行高
        _tableView.estimatedRowHeight = 80;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
        }
        _tableView.rowHeight = UITableViewAutomaticDimension;
        [_tableView registerNib:[UINib nibWithNibName:@"SISSHousingCell" bundle:nil] forCellReuseIdentifier:mapHouseCellReuseID];
        [_tableView registerNib:[UINib nibWithNibName:@"SISSPassengerCell" bundle:nil] forCellReuseIdentifier:mapPassengerCellReuseID];
        [_tableView registerClass:[SISSCommonRentCell class] forCellReuseIdentifier:commonRentCellReuseID];
    }
    return _tableView;
}

- (NSMutableArray<SISSHouseResourceModel *> *)houseResourceArr {
    if (!_houseResourceArr) {
        _houseResourceArr = [NSMutableArray array];
    }
    return _houseResourceArr;
}

- (NSMutableArray<SISSPassengerResourceModel *> *)passengerResourceArr {
    if (!_passengerResourceArr) {
        _passengerResourceArr = [NSMutableArray array];
    }
    return _passengerResourceArr;
}

- (NSMutableArray<SISSRentOutModel *> *)rentOutArr {
    if (!_rentOutArr) {
        _rentOutArr = [NSMutableArray array];
    }
    return _rentOutArr;
}

- (NSMutableArray<SISSTenantModel *> *)tenantArr {
    if (!_tenantArr) {
        _tenantArr = [NSMutableArray array];
    }
    return _tenantArr;
}

@end
